{% extends "base.html" %}
{% load staticfiles %}
{% block page_css %}
{% endblock %}
{% block page_content %}
<section class="content-header" style="padding-top:0px" xmlns="http://www.w3.org/1999/html">
<div class="row">
    <div class="box box-info">
        <div class="box-header">
            <h2>List of configured visual data network servers, datasets & detectors</h2>
        </div>
    </div>
</div>
</section>
<section class="content">
    <div class="row">
        <div class="col-lg-offset-2 col-lg-8 col-md-12">
            <div class="box box-primary">
                    <div class="box-body">
                    <table class="table table-bordered" width="100%">
                        <thead>
                        <tr>
                            <th>Server Name</th>
                            <th>Server URL</th>
                            <th>Pull datasets list</th>
                        </tr>
                        </thead>
                        <tbody>
                            {% for server in servers %}
                                <tr>
                                    <td>{{ server.name }}</td>
                                    <td><a target="_blank" href="{{ server.url }}" >{{ server.url }}</a></td>
                                    <td class="text-center"><form action="/external" method="post">{% csrf_token %}<input type="hidden" name="server_pk" value="{{ server.pk }}"/><button type="submit" class="btn btn-primary"> Load / Refresh </button></form></td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                    </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h4>Available datasets</h4>
                </div>
            <div class="box-body">
                <table class="table dataTables" width="100%">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Server</th>
                        <th>AWS Region/Bucket/ Key</th>
                        <th>Direct download</th>
                        <th>Import</th>
                    </tr>
                    </thead>
                    <tbody>
                        {% for server,datasets in available_datasets.iteritems %}
                            {% for dataset in datasets %}
                            <tr>
                                <td>{{ dataset.name }}</td>
                                <td>{{ server.name }}</td>
                                <td>{% if dataset.aws_requester_pays %} {{ dataset.aws_region }} /{{ dataset.aws_bucket }} / {{ dataset.aws_key }}{% endif %}</td>
                                <td><a href="{{ dataset.download_url }}">{{ dataset.download_url }}</a></td>
                                {% if dataset.aws_requester_pays %}
                                <td class="text-center">
                                    <form action="/import_dataset" method="post">
                                    {% csrf_token %}
                                    <input type="hidden" name="dataset_url" value="{{ dataset.url }}"/>
                                    <p class="text-danger">AWS account will be charged for bandwidth.</p>
                                    <input type="hidden" name="server_pk" value="{{ server.pk }}"/>
                                    <input type="hidden" name="dindex" value="{{ forloop.counter0 }}"/>
                                    <button type="submit" class="btn btn-danger"> Pull </button>
                                </form>
                                </td>

                                {% else %}
                                <td class="text-center"><form action="/import_dataset" method="post">
                                    {% csrf_token %}
                                    <input type="hidden" name="dataset_url" value="{{ dataset.url }}"/>
                                    <input type="hidden" name="server_pk" value="{{ server.pk }}"/>
                                    <input type="hidden" name="dindex" value="{{ forloop.counter0 }}"/>
                                    <button type="submit" class="btn btn-primary"> Pull </button>
                                </form>
                                </td>
                                {% endif %}
                            </tr>
                            {% endfor %}
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h4>Available Detectors</h4>
                </div>
            <div class="box-body">
                <table class="table dataTables" width="100%">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Server</th>
                        <th>AWS Region/Bucket/ Key</th>
                        <th>Direct download</th>
                        <th>Import</th>
                    </tr>
                    </thead>
                    <tbody>
                        {% for server,detectors in available_detectors.iteritems %}
                            {% for detector in detectors %}
                            <tr>
                                <td>{{ detector.name }}</td>
                                <td>{{ server.name }}</td>
                                <td>{% if detector.aws_requester_pays %} {{ detector.aws_region }} /{{ detector.aws_bucket }} / {{ detector.aws_key }}{% endif %}</td>
                                <td><a href="{{ detector.download_url }}">{{ detector.download_url }}</a></td>
                                {% if detector.aws_requester_pays %}
                                <td class="text-center"><form action="/import_detector" method="post">
                                    {% csrf_token %}
                                    <input type="hidden" name="detector_url" value="{{ detector.url }}"/>
                                    <p class="text-danger">AWS account will be charged for bandwidth.</p>
                                    <input type="hidden" name="server_pk" value="{{ server.pk }}"/>
                                    <input type="hidden" name="dindex" value="{{ forloop.counter0 }}"/>
                                    <button type="submit" class="btn btn-danger"> Pull </button></form>
                                </td>
                                {% else %}
                                <td class="text-center"><form action="/import_detector" method="post">
                                    {% csrf_token %}
                                    <input type="hidden" name="detector_url" value="{{ detector.url }}"/>
                                    <input type="hidden" name="server_pk" value="{{ server.pk }}"/>
                                    <input type="hidden" name="dindex" value="{{ forloop.counter0 }}"/>
                                    <button type="submit" class="btn btn-primary"> Pull </button></form></td>
                                {% endif %}
                            </tr>
                            {% endfor %}
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}
{% block page_js%}
<script>
    $(document).ready(function() {
        InitializeTables();
    })
</script>
{% endblock %}
